import * as types from './mutation-types'
import { queryAllMovie } from '../utils/api'

export const queryMovies = ({ commit, getters }, params = {}) => {
  commit(types.SET_PARAMS, params)
  return new Promise((resolve) => {
    queryAllMovie(getters.params).then(function (res) {
      if (res.success) {
        commit(types.SET_MOVIES, res.data)
        commit('setUsername', res.username)
        resolve(res.data)
      }
    })
  })
}
